package com.zcm.service.support;

import org.apache.log4j.Logger;
import org.springframework.social.connect.support.ConnectionFactoryRegistry;
import org.springframework.util.Assert;

import com.zcm.config.ApplicationConfig;
import com.zcm.org.springframework.web.context.ContextHolder;
import com.zcm.service.weibo.serviceprovider.sina.connect.SinaWeiboConnectionFactory;

/**
 * 完成服务连接框架的注册工厂的初始化
 * @author xiongj
 *
 */
public class ConnectionFacoryRegistryUtil {
	
	private static Logger log = Logger.getLogger(ConnectionFacoryRegistryUtil.class);
	private static boolean hasInit = false;
	private static ConnectionFactoryRegistry connectionFactoryRegistry = (ConnectionFactoryRegistry) ContextHolder.getBean("connectionFactoryRegistry");
	private static ApplicationConfig applicationConfig = (ApplicationConfig) ContextHolder.getBean("applicationConfig");
	
	private ConnectionFacoryRegistryUtil() {
		
	}
	
	public static void initConnectionFactoryRegistry() {
		//添加新浪微博连接工厂
		connectionFactoryRegistry.addConnectionFactory(new SinaWeiboConnectionFactory(applicationConfig.getSinaWeiboAppkey(), applicationConfig.getSinaWeiboAppSecret()));
	}
	
	public static ConnectionFactoryRegistry getConnectionFactoryRegistry() {
		return connectionFactoryRegistry;
	}
	
	public static SinaWeiboConnectionFactory getSinaConnectionFactory() {
		return (SinaWeiboConnectionFactory)getConnectionFactoryRegistry().getConnectionFactory("sinaWeibo");
	}
}
